﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using static ServerGame.Service.Dispatcher;
using ServerBase.Client;
using System;
using ServerPublic.Data;
using ServerGame.GameObject;
using static UtilPublic.Serialization.Jsh;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerGame.Data;
using static ServerGame.Manager.Efun;

namespace ServerGame.Manager
{
    /// <summary>
    /// 管理 战斗
    /// </summary>
    public static partial class CombatMgr
    {
        public static int ReceiveDamage(this MudChar obj, EProp prop, int damage, MudChar who)
        {
            if (damage < 0)
            {
                loger.Error($"ReceiveDamage 伤害值为负值。{damage}");
                return damage;
            }
            if (prop != EProp.kee && prop != EProp.sen)
            {
                loger.Error($"ReceiveDamage 伤害种类错误( 只能是 gin, kee, sen 其中之一 )。{damage}");
                return damage;
            }

            var val = obj[prop] - damage;
            if (val >= 0)
            {
                obj[prop] = val;
            }
            else
            {
                obj[prop] = -1;
            }

            //todo 昏迷设定
            return damage;
        }
        public static int ReceiveWound(this MudChar obj, EProp prop, int damage, MudChar who)
        {
            if (damage < 0)
            {
                loger.Error($"ReceiveDamage 伤害值为负值。{damage}");
                return damage;
            }
            if (prop != EProp.efkee && prop != EProp.efsen)
            {
                loger.Error($"ReceiveDamage 伤害种类错误( 只能是 efgin, efkee, efsen 其中之一 )。{damage}");
                return damage;
            }

            var val = obj[prop] - damage;
            if (val >= 0)
            {
                obj[prop] = val;
            }
            else
            {
                obj[prop] = -1;
            }
            switch (prop)
            {
                case EProp.efkee:
                    obj[EProp.kee] = Math.Min(obj[EProp.kee], obj[EProp.efkee]);
                    break;
                case EProp.efsen:
                    obj[EProp.sen] = Math.Min(obj[EProp.sen], obj[EProp.efsen]);
                    break;
                default:
                    break;
            }

            //todo 昏迷设定
            return damage;
        }
        public static string DamageMsg(int damage, string damagetype)
        {
            if (damage <= 0)
            {
                return "结果没有造成任何伤害。";
            }
            if (!ConfCbtDamageExt.TryGetValue(damagetype, out var list))
            {
                list = ConfCbtDamageExt["伤害"];
            }
            foreach (var item in list)
            {
                if (damage >= item.Vmin && damage < item.Vmax)
                {
                    return item.Desc;
                }
            }
            return "结果造成非常可怕的严重伤害！";
        }
        public static void ReportStatus(MudChar obj, bool wounded)
        {
            if (wounded)
            {
                ReportStatusEfKee(obj);
            }
            else
            {
                ReportStatusKee(obj);
            }
        }
        public static void ReportStatusKee(MudChar obj)
        {
            MessageVision($"$N{DescKee(obj[EProp.kee], obj[EProp.mxkee])}", obj);
        }
        public static void ReportStatusEfKee(MudChar obj)
        {
            MessageVision($"$N{DescEfKee(obj[EProp.efkee], obj[EProp.mxkee])}", obj);
        }
        public static void ReportStatusSen(MudChar obj)
        {
            MessageVision($"$N{DescSen(obj[EProp.sen], obj[EProp.mxsen])}", obj);
        }
    }
}
